//
//  CalendarViewController.m
//  TaxDealPlatform
//
//  Created by Zhengtong on 15/5/7.
//  Copyright (c) 2015年 Zhengtong. All rights reserved.
//

#import "CalendarViewController.h"
//#import "API.h"
//#import "RequestTool.h"
#import "JNTMailViewController.h"
#define ZTLog(...) NSLog(__VA_ARGS__)
#define DEVICE_WIDTH  [UIScreen mainScreen].bounds.size.width
#define DEVICE_HEIGHT [UIScreen mainScreen].bounds.size.height
#define BASE_SERVICE @"appBaseService?"
#define REMI_SERVICE @"appRemiService?"
#define INTE_SERVICE @"appInteService?"
#define INFO_SERVICE @"appInfoService?"
#define SERV_SERVICE @"appServService?"
#define APP_SERVICE  @"appAppService?"
@interface CalendarViewController ()

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (weak, nonatomic) IBOutlet UIButton *jianBtn;
- (IBAction)jianBtnClick:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UIButton *addBtn;
- (IBAction)addBtnClick:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UILabel *laoHuangliLabel;

@property (weak, nonatomic) IBOutlet UILabel *yearLabel;

@property (weak, nonatomic) IBOutlet UILabel *monthLabel;
@property (weak, nonatomic) IBOutlet UILabel *shenbaoLabel;

@property(nonatomic,strong)NSArray *dataArray;
@property (strong, nonatomic)UILabel *chinsesLabel;

@property (nonatomic, assign) int height;
@property (nonatomic, assign) int changyue;
@property (nonatomic, assign) int changnian;

@property (weak, nonatomic) IBOutlet UIView *candartopView;

@property (nonatomic, assign) int CurrentMonth;
@property (nonatomic, copy) NSString *CurrentAllTime;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topConstronst;


@property(nonatomic,strong)NSArray *remarkArray;

@property(nonatomic,strong)NSArray *calendarArray;
@end

@implementation CalendarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpNavgationBar];
    [self setRightBarButtonItem];
    self.topConstronst.constant = 0.0;
    [self.addBtn sizeToFit];


    //星期
    NSArray* weekdays = [NSArray arrayWithObjects:@"日", @"一", @"二", @"三", @"四", @"五", @"六", nil];
    float jianJu = (DEVICE_WIDTH - 7*20)/8;
    for (int i = 0; i < weekdays.count; i++) {
        UILabel *dayLabel = [[UILabel alloc] initWithFrame:CGRectMake(i%7*(jianJu+20)+jianJu,CGRectGetMaxY(self.candartopView.frame)-10, 20, 20)];
        dayLabel.text = weekdays[i];
        dayLabel.font = [UIFont systemFontOfSize:15];
        dayLabel.textColor = [UIColor lightGrayColor];
        [self.view addSubview:dayLabel];
    }
    self.tableView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.tableView.layer.borderWidth = 0.8f;
    _height = 0;
    _changnian = 0;
    [self setLabelDate:[NSDate date]];
    NSDate *date = [NSDate date];
    [self tongYong:date];
    
//    [self loadData];

}

- (void)viewWillLayoutSubviews
{
    self.tableView.frame = CGRectMake(0, self.tableView.frame.origin.y+80, DEVICE_WIDTH, 300);
    
    self.jianBtn.frame = CGRectMake(0, 45, self.jianBtn.frame.size.width,  self.jianBtn.frame.size.height);
    
    self.addBtn.frame = CGRectMake(DEVICE_WIDTH - self.addBtn.frame.size.width, 45, self.addBtn.frame.size.width, self.addBtn.frame.size.height);
    
    self.yearLabel.frame = CGRectMake((DEVICE_WIDTH -self.monthLabel.frame.size.width - self.laoHuangliLabel.frame.size.width-10)*0.5, 32, self.yearLabel.frame.size.width, self.yearLabel.frame.size.height);
    
    self.monthLabel.frame = CGRectMake((DEVICE_WIDTH -self.monthLabel.frame.size.width - self.laoHuangliLabel.frame.size.width-10)*0.5, CGRectGetMaxY(self.yearLabel.frame)+10, self.monthLabel.frame.size.width, self.monthLabel.frame.size.height);
    
    self.laoHuangliLabel.frame = CGRectMake(CGRectGetMaxX(self.monthLabel.frame)+10, 32, self.laoHuangliLabel.frame.size.width, self.laoHuangliLabel.frame.size.height);
    
    self.shenbaoLabel.frame   =  CGRectMake(CGRectGetMaxX(self.monthLabel.frame)+10, CGRectGetMaxY(self.laoHuangliLabel.frame)+10, self.shenbaoLabel.frame.size.width, self.shenbaoLabel.frame.size.height);
    
    
}
//今年时间
- (NSString *)currentYear
{
    NSDate *date = [NSDate date];
    NSDateFormatter* ff = [[NSDateFormatter alloc] init];
    [ff setDateFormat:@"yyyy"];
    NSString* dateStr = [ff stringFromDate:date];
    return dateStr;
}

#pragma mark - 设置导航条
- (void)setUpNavgationBar
{
    self.title = @"申请";
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    self.navigationController.navigationBar.translucent = NO;
    UIBarButtonItem *leftBackBtnItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginalName:@"返回按钮.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBtnClick)];
    self.navigationItem.leftBarButtonItem = leftBackBtnItem;
}


- (void)setRightBarButtonItem
{
    
    UIBarButtonItem *rightBackBtnItem = [[UIBarButtonItem alloc]initWithTitle:@"新增" style:UIBarButtonItemStylePlain target:self action:@selector(rightBtnClick)];
    [rightBackBtnItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size:14.0]} forState:UIControlStateNormal];
    
    self.navigationItem.rightBarButtonItem = rightBackBtnItem;
}





#pragma mark ---按钮回调--

- (void)leftBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)rightBtnClick
{
    JNTMailViewController *mailVC = [[JNTMailViewController alloc]init];
    [self.navigationController pushViewController:mailVC animated:YES];
}

-(void)setLabelDate:(NSDate*)date
{
    NSDateFormatter* ff = [[NSDateFormatter alloc] init];
    [ff setDateFormat:@"yyyy-M-dd"];
    NSString* dateStr = [ff stringFromDate:date];
    NSArray *dateArray = [dateStr componentsSeparatedByString:@"-"];
    self.yearLabel.text = dateArray[0];
    self.monthLabel.text = [dateArray[1] stringByAppendingString:@"月"];
    self.CurrentMonth = [dateArray[1] intValue];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return  300;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell  *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    
    NSDate *today = [formatter dateFromString:_CurrentAllTime]; //Get a date object for today's date
    NSCalendar *c = [NSCalendar currentCalendar];
    NSRange days = [c rangeOfUnit:NSCalendarUnitDay
                           inUnit:NSCalendarUnitMonth
                          forDate:today];
    //一号多少天】
    int numDay = (int)days.length;
    //一号星期几
    NSCalendar *localeCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
    
    unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay|NSCalendarUnitWeekday|NSCalendarUnitEra;
    
    NSArray *yihaoArray = [_CurrentAllTime componentsSeparatedByString:@"-"];
    
    NSString *tmpyihao = [NSString stringWithFormat:@"%@-%@-01",[yihaoArray objectAtIndex:0],[yihaoArray objectAtIndex:1]];
    
    NSDateComponents *localeComp = [localeCalendar components:unitFlags fromDate:[formatter dateFromString:tmpyihao]];
    //一号的位置
    int location = (int)[localeComp weekday];
    
     float jianJu = ([UIScreen mainScreen].bounds.size.width-20*7)/8;
    NSMutableArray *dayRedArr = [NSMutableArray array];
     NSMutableArray *chineseArr = [NSMutableArray array];
    NSString *string;
    for (int i = location-1; i<numDay+location-1; i++)
    {
        UILabel *la = [[UILabel alloc] initWithFrame:CGRectMake(i%7*(jianJu+20)+jianJu-10, i/7*(jianJu+20+5)+jianJu, 40, 20)];
        la.text = [@(i-location+2) stringValue];
        la.textAlignment = NSTextAlignmentCenter;

        [dayRedArr addObject:la];
        
        _chinsesLabel = [[UILabel alloc] initWithFrame:CGRectMake(i%7*(jianJu+20)+jianJu-3, i/7*(jianJu+20+5)+18+jianJu, 40, 20)];
        _chinsesLabel.font = [UIFont systemFontOfSize:12];
      NSString *lunar =  [self LunarForSolarYear:[[yihaoArray objectAtIndex:0] intValue] Month:[[yihaoArray objectAtIndex:1] intValue]Day:(i-location+2)];
       NSString* lunarDay =  [[lunar componentsSeparatedByString:@"-"] objectAtIndex:1];
    NSString* month =  [[lunar componentsSeparatedByString:@"-"] objectAtIndex:0];
        _chinsesLabel.text =lunarDay;
        
        [chineseArr addObject:_chinsesLabel];
        
        
        if ([lunarDay isEqualToString:@"初一"]) {
            _chinsesLabel.text = [NSString stringWithFormat:@"%@月",month];
        }
          NSString *dateStr = [NSString stringWithFormat:@"%@-%@-%@",[yihaoArray objectAtIndex:0],[yihaoArray objectAtIndex:1],[@(i-location+2) stringValue]];
        
        if ([self isEqualTo:dateStr]) {
            string = dateStr;
            //la.textColor = [UIColor whiteColor];
            //_chinsesLabel.textColor = [UIColor whiteColor];
            UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(i%7*(jianJu+20)+jianJu-10, i/7*(jianJu+20+5)+jianJu, 40, 40)];
            //mainView.backgroundColor = [UIColor redColor];
            mainView.layer.borderColor = [UIColor redColor].CGColor;
            mainView.layer.borderWidth = 1.0f;
            mainView.layer.cornerRadius = 20.0f;
            mainView.layer.masksToBounds = YES;
            [cell addSubview:mainView];
            
        }
          [cell addSubview:la];
        [self changeMonth:month withDay:lunarDay];
        [self lunchMonth:[[yihaoArray objectAtIndex:1] intValue] with:(i-location+2)];
        [cell addSubview:_chinsesLabel];
    }
     NSString *dateStr = [self currentYear];
    if([self.yearLabel.text isEqualToString:dateStr]){
        UILabel *la;
        UILabel *chineseLabel;
        for (int  k = 0; k < [self.remarkArray[self.CurrentMonth] intValue]; k++) {
            la = (UILabel *)dayRedArr[k];
            la.textColor = [UIColor redColor];
            
            chineseLabel = (UILabel *)chineseArr[k];
            chineseLabel.textColor = [UIColor redColor];
            
            NSString *dateStr = [NSString stringWithFormat:@"%@-%@-%@",@"2015",[NSString stringWithFormat:@"%d",self.CurrentMonth],[NSString stringWithFormat:@"%d",k+1]];
            if([self isEqualTo:dateStr]){
                la.textColor = [UIColor whiteColor];
                chineseLabel.textColor = [UIColor whiteColor];
            }
        }
    }
    
    return cell;
}
-(void)changeMonth:(NSString *)month withDay:(NSString *)day
{
    if([month isEqualToString:@"正"] &&
       [day isEqualToString:@"初一"]){
        
        //正月初一：春节
       _chinsesLabel.text = @"春节";
        
    }else if([ month isEqualToString:@"正"] &&
             [day isEqualToString:@"十五"]){
        
        
        //正月十五：元宵节
        _chinsesLabel.text = @"元宵";
        
    }else if([month isEqualToString:@"二"] &&
             [day isEqualToString:@"初二"]){
        
        //二月初二：春龙节(龙抬头)
        _chinsesLabel.text = @"龙抬头";
        
    }else if([month isEqualToString:@"五"] &&
             [day isEqualToString:@"初五"]){
        
        //五月初五：端午节
        _chinsesLabel.text = @"端午";
        
    }else if([month isEqualToString:@"七"] &&
             [day isEqualToString:@"初七"]){
        
        //七月初七：七夕情人节
        _chinsesLabel.text = @"七夕";
        
    }else if([month isEqualToString:@"八"] &&
             [day isEqualToString:@"十五"]){
        
        //八月十五：中秋节
        _chinsesLabel.text= @"中秋";
        
    }else if([month isEqualToString:@"九"] &&
             [day isEqualToString:@"初九"]){
        
        //九月初九：重阳节、中国老年节（义务助老活动日）
       _chinsesLabel.text = @"重阳";
        
    }else if([month isEqualToString:@"腊"] &&
             [day isEqualToString:@"初八"]){
        
        //腊月初八：腊八节
       _chinsesLabel.text = @"腊八";
        
    }else if([month isEqualToString:@"腊"] &&
             [day isEqualToString:@"二十四"]){
        
        
        //腊月二十四 小年
        _chinsesLabel.text = @"小年";
        
    }else if([month isEqualToString:@"腊"] &&
             [day isEqualToString:@"三十"]){
        
        //腊月三十（小月二十九）：除夕
        _chinsesLabel.text= @"除夕";
        
    }
    
    

}
-(void)lunchMonth:( int)month with:(int)day
{

    //===================================
    //1.1元旦
    if (month == 1 &&
        day == 1){
         _chinsesLabel.text = @"元旦";
        
        //2.14情人节
    }else if (month == 2 &&
              day == 14){
        _chinsesLabel.text = @"情人节";
        
        //3.8妇女节
    }else if (month == 3 &&
              day == 8){
         _chinsesLabel.text = @"妇女节";
        
        //5.1劳动节
    }else if (month == 5 &&
              day == 1){
 _chinsesLabel.text = @"劳动节";
        
        //6.1儿童节
    }else if (month == 6 &&
              day == 1){
         _chinsesLabel.text= @"儿童节";
        
        //8.1建军节
    }else if (month == 8 &&
              day == 1){
         _chinsesLabel.text = @"建军节";
        
        //9.10教师节
    }else if (month == 9 &&
              day == 10){
         _chinsesLabel.text = @"教师节";
        
        //10.1国庆节
    }else if (month == 10 &&
              day == 1){
         _chinsesLabel.text= @"国庆节";
        
        //11.1植树节
    }else if (month == 11 &&
              day == 1){
         _chinsesLabel.text = @"植树节";
        
        //11.11光棍节
    }else if (month == 11 &&
              day == 11){
         _chinsesLabel.text = @"光棍节";
        
    }else{
        
        
        //            这里写其它的节日
        
    }

}
//判断是不是同一天
- (BOOL)isEqualTo:(NSString *)nowDate
{
    NSArray *array = [nowDate componentsSeparatedByString:@"-"];
    int month = [array[1] intValue];
    int year = [array[0] intValue];
     int day = [array[2] intValue];
    
    NSDateFormatter* ff = [[NSDateFormatter alloc] init];
    [ff setDateFormat:@"yyyy-M-dd"];
    NSString* dateStr = [ff stringFromDate:[NSDate date]];
    NSArray *dateArray = [dateStr componentsSeparatedByString:@"-"];
    int month1 = [dateArray[1] intValue];
    int year1 = [dateArray[0] intValue];
    int day1 = [dateArray[2] intValue];
    
    BOOL isEqual = (year == year1)&&(month == month1)&&(day == day1);
    return isEqual;
}
-(NSString *)LunarForSolarYear:(int)wCurYear Month:(int)wCurMonth Day:(int)wCurDay{
    //农历日期名
    NSArray *cDayName =  [NSArray arrayWithObjects:@"*",@"初一",@"初二",@"初三",@"初四",@"初五",@"初六",@"初七",@"初八",@"初九",@"初十",
                          @"十一",@"十二",@"十三",@"十四",@"十五",@"十六",@"十七",@"十八",@"十九",@"二十",
                          @"廿一",@"廿二",@"廿三",@"廿四",@"廿五",@"廿六",@"廿七",@"廿八",@"廿九",@"三十",nil];
    
    //农历月份名
    NSArray *cMonName =  [NSArray arrayWithObjects:@"*",@"正",@"二",@"三",@"四",@"五",@"六",@"七",@"八",@"九",@"十",@"十一",@"腊",nil];
    
    //公历每月前面的天数
    const int wMonthAdd[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
    
    //农历数据
    const int wNongliData[100] = {2635,333387,1701,1748,267701,694,2391,133423,1175,396438
        ,3402,3749,331177,1453,694,201326,2350,465197,3221,3402
        ,400202,2901,1386,267611,605,2349,137515,2709,464533,1738
        ,2901,330421,1242,2651,199255,1323,529706,3733,1706,398762
        ,2741,1206,267438,2647,1318,204070,3477,461653,1386,2413
        ,330077,1197,2637,268877,3365,531109,2900,2922,398042,2395
        ,1179,267415,2635,661067,1701,1748,398772,2742,2391,330031
        ,1175,1611,200010,3749,527717,1452,2742,332397,2350,3222
        ,268949,3402,3493,133973,1386,464219,605,2349,334123,2709
        ,2890,267946,2773,592565,1210,2651,395863,1323,2707,265877};
    
    static int nTheDate,nIsEnd,m,k,n,i,nBit;
    
    
    //计算到初始时间1921年2月8日的天数：1921-2-8(正月初一)
    nTheDate = (wCurYear - 1921) * 365 + (wCurYear - 1921) / 4 + wCurDay + wMonthAdd[wCurMonth - 1] - 38;
    
    if((!(wCurYear % 4)) && (wCurMonth > 2))
        nTheDate = nTheDate + 1;
    
    //计算农历天干、地支、月、日
    nIsEnd = 0;
    m = 0;
    while(nIsEnd != 1)
    {
        if(wNongliData[m] < 4095)
            k = 11;
        else
            k = 12;
        n = k;
        while(n>=0)
        {
            //获取wNongliData(m)的第n个二进制位的值
            nBit = wNongliData[m];
            for(i=1;i<n+1;i++)
                nBit = nBit/2;
            
            nBit = nBit % 2;
            
            if (nTheDate <= (29 + nBit))
            {
                nIsEnd = 1;
                break;
            }
            
            nTheDate = nTheDate - 29 - nBit;
            n = n - 1;
        }
        if(nIsEnd)
            break;
        m = m + 1;
    }
    wCurYear = 1921 + m;
    wCurMonth = k - n + 1;
    wCurDay = nTheDate;
    if (k == 12)
    {
        if (wCurMonth == wNongliData[m] / 65536 + 1)
            wCurMonth = 1 - wCurMonth;
        else if (wCurMonth > wNongliData[m] / 65536 + 1)
            wCurMonth = wCurMonth - 1;
    }
    
    
    //生成农历月
    NSString *szNongliMonth;
    if (wCurMonth < 1){
        szNongliMonth = [NSString stringWithFormat:@"闰%@",(NSString *)[cMonName objectAtIndex:-1 * wCurMonth]];
    }else{
        szNongliMonth = (NSString *)[cMonName objectAtIndex:wCurMonth];
    }
    
    //生成农历日
    NSString *szNongliDay = [cDayName objectAtIndex:wCurDay];
    
    //合并
    NSString *lunarDate = [NSString stringWithFormat:@"%@-%@",szNongliMonth,szNongliDay];
    
    return lunarDate;
}

- (IBAction)jianBtnClick:(UIButton *)sender {
    NSArray *array = [_CurrentAllTime componentsSeparatedByString:@"-"];
    int month = [array[1] intValue]-1;
    int year = [array[0] intValue];
    if (month == 0)
    {
        month = 12;
        --year;
    }
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *nowData = [formatter dateFromString:[NSString stringWithFormat:@"%d-%d-%@",year,month,[array objectAtIndex:2]]];
    [self tongYong:nowData];
    [self.tableView reloadData];

}

- (IBAction)addBtnClick:(UIButton *)sender {
    
    NSArray *array = [_CurrentAllTime componentsSeparatedByString:@"-"];
    int month = [array[1] intValue]+1;
    int year = [array[0] intValue];
    if (month == 13)
    {
        month = 1;
        ++year;
    }
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *nowData = [formatter dateFromString:[NSString stringWithFormat:@"%d-%d-%@",year,month,[array objectAtIndex:2]]];
    [self tongYong:nowData];
    [self.tableView reloadData];
}
-(void)tongYong:(NSDate*)nowData
{
    NSString *dateStr = [self getChineseCalendarWithDate:nowData];
    [self setLabelDate:nowData];
    NSString *chineseDate = [[dateStr componentsSeparatedByString:@"阴历"] objectAtIndex:1];
    self.laoHuangliLabel.text =  [NSString stringWithFormat:@"%@\n%@",[[chineseDate componentsSeparatedByString:@"古法日期"] objectAtIndex:0],[[chineseDate componentsSeparatedByString:@"古法日期"] objectAtIndex:1]];
    _CurrentAllTime = [[dateStr componentsSeparatedByString:@"阴历"] objectAtIndex:0];
}
//返回值 古法 字符串 月  日   传参 当前日历阳历  1号
-(NSString*)getChineseCalendarWithDate:(NSDate *)date{
    NSArray *chineseYears = [NSArray arrayWithObjects:
                             @"甲子", @"乙丑", @"丙寅",    @"丁卯",    @"戊辰",    @"己巳",    @"庚午",    @"辛未",    @"壬申",    @"癸酉",
                             @"甲戌",    @"乙亥",    @"丙子",    @"丁丑", @"戊寅",    @"己卯",    @"庚辰",    @"辛己",    @"壬午",    @"癸未",
                             @"甲申",    @"乙酉",    @"丙戌",    @"丁亥",    @"戊子",    @"己丑",    @"庚寅",    @"辛卯",    @"壬辰",    @"癸巳",
                             @"甲午",    @"乙未",    @"丙申",    @"丁酉",    @"戊戌",    @"己亥",    @"庚子",    @"辛丑",    @"壬寅",    @"癸丑",
                             @"甲辰",    @"乙巳",    @"丙午",    @"丁未",    @"戊申",    @"己酉",    @"庚戌",    @"辛亥",    @"壬子",    @"癸丑",
                             @"甲寅",    @"乙卯",    @"丙辰",    @"丁巳",    @"戊午",    @"己未",    @"庚申",    @"辛酉",    @"壬戌",    @"癸亥", nil];
    
    NSArray *chineseMonths=[NSArray arrayWithObjects:
                            @"正月", @"二月", @"三月", @"四月", @"五月", @"六月", @"七月", @"八月",
                            @"九月", @"十月", @"冬月", @"腊月", nil];
    
    
    NSArray *chineseDays=[NSArray arrayWithObjects:
                          @"初一", @"初二", @"初三", @"初四", @"初五", @"初六", @"初七", @"初八", @"初九", @"初十",
                          @"十一", @"十二", @"十三", @"十四", @"十五", @"十六", @"十七", @"十八", @"十九", @"二十",
                          @"廿一", @"廿二", @"廿三", @"廿四", @"廿五", @"廿六", @"廿七", @"廿八", @"廿九", @"三十",  nil];
    NSArray *chiineseSelfData = [NSArray arrayWithObjects:
                                 @"甲子", @"乙丑", @"丙寅",    @"丁卯",    @"戊辰",    @"己巳",    @"庚午",    @"辛未",    @"壬申",    @"癸酉",
                                 @"甲戌",    @"乙亥",    @"丙子",    @"丁丑", @"戊寅",    @"己卯",    @"庚辰",    @"辛己",    @"壬午",    @"癸未",
                                 @"甲申",    @"乙酉",    @"丙戌",    @"丁亥",    @"戊子",    @"己丑",    @"庚寅",    @"辛卯",    @"壬辰",    @"癸巳",
                                 @"甲午",    @"乙未",    @"丙申",    @"丁酉",    @"戊戌",    @"己亥",    @"庚子",    @"辛丑",    @"壬寅",    @"癸丑",
                                 @"甲辰",    @"乙巳",    @"丙午",    @"丁未",    @"戊申",    @"己酉",    @"庚戌",    @"辛亥",    @"壬子",    @"癸丑",
                                 @"甲寅",    @"乙卯",    @"丙辰",    @"丁巳",    @"戊午",    @"己未",    @"庚申",    @"辛酉",    @"壬戌",    @"癸亥", nil];
    
    
    NSArray *weakDate = [NSArray arrayWithObjects:
                         @"星期日",@"星期一", @"星期二", @"星期三", @"星期四", @"星期五", @"星期六", nil];
    NSCalendar *localeCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
 
    unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay|NSCalendarUnitWeekday|NSCalendarUnitEra;
    
    NSDateComponents *localeComp = [localeCalendar components:unitFlags fromDate:date];//localeComp.date
    
 
    
    NSDateFormatter *formater = [[NSDateFormatter alloc] init];
    [formater setDateFormat:@"yyyy-MM-dd"];
    
    int dayNum = [date timeIntervalSinceDate:[formater dateFromString:@"1970-02-13"]]/60/60/24;
    ZTLog(@"dayNum==%d",dayNum);
    //古法  月
    
    NSArray *tmpNowDataA = [[formater stringFromDate:date] componentsSeparatedByString:@"-"];
    NSArray *sinceDataA = [[formater stringFromDate:[formater dateFromString:@"1970-01-01"]] componentsSeparatedByString:@"-"];
    int monNum = ([[tmpNowDataA objectAtIndex:0] intValue]-[[sinceDataA objectAtIndex:0] intValue])*12+[[tmpNowDataA objectAtIndex:1] intValue];
    
    //    NSLog(@"阴历日%@",[chiineseSelfData objectAtIndex:dayNum%60]);
    //    NSLog(@"阴历月%@",[chiineseSelfData objectAtIndex:monNum%12]);
    //
    NSString *y_str = [chineseYears objectAtIndex:localeComp.year-1];
    NSString *m_str = [chineseMonths objectAtIndex:localeComp.month-1];
    NSString *d_str = [chineseDays objectAtIndex:localeComp.day-1];
    
    NSString *chineseCal_str =[NSString stringWithFormat: @"农历%@ %@",m_str,d_str];
    
    //,m_str,d_str,[chineseDays objectAtIndex:localeComp.weekday],gufariqi
    NSString *gufariqi = [NSString stringWithFormat:@"%@年%@月%@日",y_str,[chiineseSelfData objectAtIndex:monNum%12],[chiineseSelfData objectAtIndex:dayNum%60]];
    
    NSString *zuizhong = [NSString stringWithFormat:@"%@阴历%@%@古法日期%@",[formater stringFromDate:date],chineseCal_str,[weakDate objectAtIndex:(localeComp.weekday-1)],gufariqi];
    
    
    
    //    return chineseCal_str;
    return zuizhong;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
@end
